package com.zis.auction.web;

import com.alibaba.fastjson.JSONObject;
import com.zis.auction.model.Counsel;
import com.zis.auction.service.ICounselInter;
import com.zis.core.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create by wangshen 2018/1/16
 */
@RestController
@RequestMapping("/api/open/auction/counsel")
public class CounselRestful {

    @Autowired
    private ICounselInter counselInter;


    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    @ResponseBody
    public String add(@RequestBody JSONObject jsonObject) throws Exception {
        String title = jsonObject.getString("title");
        String content = jsonObject.getString("content");
        String ausId = jsonObject.getString("ausId");
        if (ausId.equals("")) {
            return ResponseEntity.createNULLJsonResponse("微信用户信息位获取到");
        }
        if (title.equals("")) {
            return ResponseEntity.createNULLJsonResponse("请输入咨询的问题");
        }
        Counsel counsel = new Counsel();
        counsel.setTitle(title);
        counsel.setContent(content);
        counsel.setAusId(ausId);
        return counselInter.insert(counsel);
    }

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Counsel select(@PathVariable("id") String id) throws Exception {
        return counselInter.selectById(id);
    }

    @RequestMapping(value = "/list/{ausId}", method = RequestMethod.GET)
    @ResponseBody
    public List<Counsel> findByAusId(@PathVariable("ausId") String ausId) throws Exception {
        return counselInter.findByAusId(ausId);
    }
}
